<template>
  <div class="app-container">
    <!-- <el-form ref="userPet" :model="userPet" label-width="120px">
      <el-form-item label="id">
        <label> {{ userPet.id }} </label>
      </el-form-item>
      <el-form-item label="宠物经验药水">
        <label> {{ userPet.expNum }} </label>
      </el-form-item>
      <el-form-item label="宠物饲料">
        <label> {{ userPet.foodNum }} </label>
      </el-form-item>
      <el-form-item label="当前选择的宠物">
        <label> {{ userPet.selectTid }} </label>
      </el-form-item>
    </el-form> -->

    <el-table :data="heroList" style="width: 100%;margin-top:30px;" border>
      <el-table-column align="center" label="ID" width="50">
        <template slot-scope="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="tid" width="220">
        <template slot-scope="scope">{{ scope.row._id }}</template>
      </el-table-column>
      <el-table-column align="center" label="英雄tid" width="100">
        <template slot-scope="scope">{{ scope.row.tid }}</template>
      </el-table-column>
      <el-table-column align="center" label="英雄装备">
        <template slot-scope="scope">{{ jsonObjToStr(scope.row.Goods) }}</template>
      </el-table-column>
      <el-table-column align="center" label="英雄技能" width="100">
        <template slot-scope="scope">{{ scope.row.skillId }}</template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getUserHeroInfo } from '@/api/userhero'

export default {
  filters: {
    formatDate(time) {
      var hh = parseInt(time) / parseInt(3600)
      time %= 3600
      var mm = time / 60
      var ss = time % 60
      return hh + ':' + mm + ':' + ss
    }
  },
  data() {
    return {
      members: [],
      // userPet: {
      //   id: '',
      //   expNum: 0,
      //   foodNum: 0,
      //   selectTid: 0,
      //   pets: null
      // },
      heroList: []
    }
  },
  created() {
    const id = this.$route.params && this.$route.params.uid
    this.fetchData(id)
  },
  methods: {
    fetchData(id) {
      getUserHeroInfo(id).then(response => {
        var heros = response.data.heroinfo
        this.heroList = []
        for (var idx in heros) {
          this.heroList.push(heros[idx])
        }
      })
    },
    jsonObjToStr(obj) {
      if (obj === []) {
        return '[]'
      }
      if (obj == null) {
        return 'null'
      }
      return JSON.stringify(obj)
    }
  }
}
</script>
